@@ -10,6 +10,19 @@ from mch.models import BrandInfo, DistributorInfo, LatestAppInfo, ModelInfo, Ope  | 
            ||
| 10 | 10 | 
                from utils.error.errno_utils import OperatorStatusCode  | 
            
| 11 | 11 | 
                 | 
            
| 12 | 12 | 
                 | 
            
| 13 | 
                +def bmd_infos(operator):  | 
            |
| 14 | 
                +    brands = BrandInfo.objects.filter(brand_id=operator.brand_id, status=True).order_by('position')
               | 
            |
| 15 | 
                + brands = [brand.data for brand in brands]  | 
            |
| 16 | 
                +  | 
            |
| 17 | 
                +    models = ModelInfo.objects.filter(brand_id=operator.brand_id, status=True).order_by('position')
               | 
            |
| 18 | 
                + models = [model.data for model in models]  | 
            |
| 19 | 
                +  | 
            |
| 20 | 
                +    distributors = DistributorInfo.objects.filter(brand_id=operator.brand_id, status=True).order_by('position')
               | 
            |
| 21 | 
                + distributors = [distributor.data for distributor in distributors]  | 
            |
| 22 | 
                +  | 
            |
| 23 | 
                + return brands, models, distributors  | 
            |
| 24 | 
                +  | 
            |
| 25 | 
                +  | 
            |
| 13 | 26 | 
                @logit  | 
            
| 14 | 27 | 
                def login_api(request):  | 
            
| 15 | 28 | 
                     phone = request.POST.get('phone', '')
               | 
            
                @@ -26,16 +39,32 @@ def login_api(request):  | 
            ||
| 26 | 39 | 
                if not check_password(password, operator.encryption):  | 
            
| 27 | 40 | 
                return response(OperatorStatusCode.OPERATOR_PASSWORD_ERROR)  | 
            
| 28 | 41 | 
                 | 
            
| 29 | 
                -    brands = BrandInfo.objects.filter(brand_id=operator.brand_id, status=True).order_by('position')
               | 
            |
| 30 | 
                - brands = [brand.data for brand in brands]  | 
            |
| 42 | 
                + brands, models, distributors = bmd_infos(operator)  | 
            |
| 31 | 43 | 
                 | 
            
| 32 | 
                -    models = ModelInfo.objects.filter(brand_id=operator.brand_id, status=True).order_by('position')
               | 
            |
| 33 | 
                - models = [model.data for model in models]  | 
            |
| 44 | 
                +    return response(200, data={
               | 
            |
| 45 | 
                + 'optor_id': operator.operator_id,  | 
            |
| 46 | 
                + 'brands': brands,  | 
            |
| 47 | 
                + 'models': models,  | 
            |
| 48 | 
                + 'distributors': distributors,  | 
            |
| 49 | 
                + })  | 
            |
| 34 | 50 | 
                 | 
            
| 35 | 
                -    distributors = DistributorInfo.objects.filter(brand_id=operator.brand_id, status=True).order_by('position')
               | 
            |
| 36 | 
                - distributors = [distributor.data for distributor in distributors]  | 
            |
| 51 | 
                +  | 
            |
| 52 | 
                +@logit  | 
            |
| 53 | 
                +def bmd_infos(request):  | 
            |
| 54 | 
                +    optor_id = request.POST.get('optor_id', '')
               | 
            |
| 55 | 
                +  | 
            |
| 56 | 
                + try:  | 
            |
| 57 | 
                + operator = OperatorInfo.objects.get(optor_id=optor_id, status=True)  | 
            |
| 58 | 
                + except OperatorInfo.DoesNotExist:  | 
            |
| 59 | 
                + return response(OperatorStatusCode.OPERATOR_NOT_FOUND)  | 
            |
| 60 | 
                +  | 
            |
| 61 | 
                + if operator.user_status == OperatorInfo.DISABLED:  | 
            |
| 62 | 
                + return response(OperatorStatusCode.OPERATOR_NOT_ACTIVATED)  | 
            |
| 63 | 
                +  | 
            |
| 64 | 
                + brands, models, distributors = bmd_infos(operator)  | 
            |
| 37 | 65 | 
                 | 
            
| 38 | 66 | 
                     return response(200, data={
               | 
            
| 67 | 
                + 'optor_id': operator.operator_id,  | 
            |
| 39 | 68 | 
                'brands': brands,  | 
            
| 40 | 69 | 
                'models': models,  | 
            
| 41 | 70 | 
                'distributors': distributors,  | 
            
                @@ -192,6 +192,7 @@ urlpatterns += [  | 
            ||
| 192 | 192 | 
                url(r'^api/brands$', mch_views.brands_list, name='brands_list'),  | 
            
| 193 | 193 | 
                url(r'^api/models$', mch_views.models_list, name='models_list'),  | 
            
| 194 | 194 | 
                url(r'^api/distributors$', mch_views.distributors_list, name='distributors_list'),  | 
            
| 195 | 
                + url(r'^api/infos$', mch_views.bmd_infos, name='bmd_infos'),  | 
            |
| 195 | 196 | 
                ]  | 
            
| 196 | 197 | 
                 | 
            
| 197 | 198 | 
                urlpatterns += [  |